package com.by.flutter_init

import android.content.Context
import android.util.Log
import cn.jpush.android.api.CmdMessage
import cn.jpush.android.api.CustomMessage
import cn.jpush.android.api.JPushMessage
import cn.jpush.android.api.NotificationMessage
import cn.jpush.android.service.JPushMessageReceiver

/**
 * 极光推送消息接收器
 * 
 * 继承JPushMessageReceiver，用于接收极光推送的各种回调
 * 包括：Tag/Alias设置结果、通知消息、自定义消息等
 */
class JPushReceiver : JPushMessageReceiver() {
    
    companion object {
        private const val TAG = "JPushReceiver"
    }
    
    /**
     * Tag 增加回调
     */
    override fun onTagOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
        super.onTagOperatorResult(context, jPushMessage)
        Log.d(TAG, "onTagOperatorResult: $jPushMessage")
    }
    
    /**
     * Alias 设置回调
     */
    override fun onAliasOperatorResult(context: Context?, jPushMessage: JPushMessage?) {
        super.onAliasOperatorResult(context, jPushMessage)
        Log.d(TAG, "onAliasOperatorResult: $jPushMessage")
    }
    
    /**
     * 通知消息到达回调（App在前台）
     */
    override fun onNotifyMessageArrived(context: Context?, message: NotificationMessage?) {
        super.onNotifyMessageArrived(context, message)
        Log.d(TAG, "onNotifyMessageArrived: ${message?.notificationTitle} - ${message?.notificationContent}")
    }
    
    /**
     * 通知消息被点击回调
     */
    override fun onNotifyMessageOpened(context: Context?, message: NotificationMessage?) {
        super.onNotifyMessageOpened(context, message)
        Log.d(TAG, "onNotifyMessageOpened: ${message?.notificationTitle}")
    }
    
    /**
     * 自定义消息接收回调
     */
    override fun onMessage(context: Context?, customMessage: CustomMessage?) {
        super.onMessage(context, customMessage)
        Log.d(TAG, "onMessage: ${customMessage?.message}")
    }
    
    /**
     * 连接状态变化回调
     */
    override fun onConnected(context: Context?, isConnected: Boolean) {
        super.onConnected(context, isConnected)
        Log.d(TAG, "onConnected: $isConnected")
    }
    
    /**
     * 命令消息回调
     */
    override fun onCommandResult(context: Context?, cmdMessage: CmdMessage?) {
        super.onCommandResult(context, cmdMessage)
        Log.d(TAG, "onCommandResult: $cmdMessage")
    }
}

